<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            position: absolute;
            left: 0;
            height: 100px;
            width: 100px;
            background-color: purple;
        }
        
        span {
            position: absolute;
            left: 200px;
            height: 100px;
            width: 100px;
            background-color: purple;
        }
    </style>
</head>

<body>
    <div></div>
    <span></span>
    <script>
        var div = document.querySelector("div");
        var span = document.querySelector("span");
        //目标对象目标位置
        function animate(obj, target) {
            //获取当前位置
            var time = setInterval(function() {
                if (obj.offsetLeft >= target) {
                    clearInterval(time);
                }
                obj.style.left = obj.offsetLeft + 10 + "px";
            }, 100)
        }
        //调用
        animate(div, 400);
        animate(span, 800);
    </script>
</body>

</html>